#!/usr/bin/env zsh
# Description:
#   Lazy-load

local    arg="$1" package
local -a parsed_zplugs
local    lazy
local    default="no"

package="${arg}, ${zplugs[$arg]%, }"
parsed_zplugs=(${(s/, /)package/,  */, })

lazy="${parsed_zplugs[(k)lazy:*]#lazy:*}"
if [[ -z $lazy ]]; then
    zstyle -t ":zplug:tag" lazy
    case $status in
        0)
            # word that means true
            zstyle -b ":zplug:tag" lazy lazy
            ;;
        1)
            # word that means false
            if [[ $lazy =~ ^("${(j:|:)_zplug_boolean_true[@]}|${(j:|:)_zplug_boolean_false[@]}")$ ]]; then
                # ok (false words)
                :
            else
                __zplug::io::print::f \
                    --die \
                    --zplug \
                    --error \
                    --func \
                    "lazy tag must be a boolean ($fg[green]$arg$reset_color)\n"
                return 1
            fi
            ;;
        2)
            # undefined
            ;;
    esac
fi

: ${lazy:=$default}
if [[ $lazy =~ ^("${(j:|:)_zplug_boolean_true[@]}|${(j:|:)_zplug_boolean_false[@]}")$ ]]; then
    :
else
    __zplug::io::print::f \
        --die \
        --zplug \
        --error \
        --func \
        "lazy tag must be a boolean ($fg[green]$arg$reset_color)\n"
    return 1
fi

echo "$lazy"
